<apex:page standardController="Forecast__c"	extensions="trac_ForecastControllerExt">
	<c:trac_AccountForecast />

	<script type="text/javascript">
		var $j = jQuery.noConflict();
		var tmp = null; 
		var fy = {!Forecast__c.Year__c};
		var groups = ["Booking", "Passenger", "Marketing"];
		var _comment = null;
		
		$j(document).ready(function() {
			$j(".buttonSet").hide();
			
			// setup tabs
			$j(".tabContent").not(":first").show().hide(); // trick browser
			$j(".tabLink").first().addClass("active");
			$j("#tabWrapper").height($j(".tabContent").first().height());
			
			
			$j(".tabLink").click(function() {
				var newTab = $j(".tabContent").eq($j(this).parent().index());
				var oldTab = $j(".tabContent:visible");				  
				
				oldTab.hide('slide', {direction: 'left'}, 0);
				newTab.show('slide', {direction: 'right'}, 0);
				
				//$j(".tabContent:visible").hide();
				//$j(".tabContent").eq($j(this).parent().index()).show();

				$j(".tabLink").not(this).removeClass("active");
				$j(this).addClass("active");
			});
			
			
			$j(".anInput").focus(function() {
				tmp = $j(this).val();
				$j(this).addClass('active');
			}).blur(function() {
				if (isNaN($j(this).val()) || $j.trim($j(this).val()) == "") {
					$j(this).val(tmp);
				}
				$j(this).removeClass('active');
			}).change(function() {
				$j(".buttonSet:not(:visible)").show();
			});
			
			$j("#saveScreen").dialog({ height: 70, width: 270, modal: true,  resizable: false, autoOpen: false, closeOnEscape: false});
			
			$j("#commentEditor").dialog({ height: 250, width: 270, title: "Comments", modal: true,  resizable: false, autoOpen: false, closeOnEscape: true,
				buttons: [
					{ 
						text: "Ok", 
						click: function() {
							$j(_comment).val($j("#comment").val());
							$j(this).dialog("close")
						}
					},
					{ 
						text: "Cancel", 
						click: function() {
							$j(this).dialog("close")
						}
					}
				]
				 
			 });
			
			
			$j(".commentInput").click(function() {
				_comment = this;
				$j("#commentEditor").dialog("open");
				$j("#comment").val($j(this).val()).focus();
				$j(this).blur();
			});
			
			
			
			// 3 birds 1 stone
			calculateSummary("forecast");
			calculateSummary("actual");
			calculateSummary("prior-year-actual");
			
			calculateVarianceSummary();
			calculatePriorYearVarianceSummary();
			
			calculateTotals();
			calculateAnnualTotals();
			
		});

		
		// ANNUAL TOTALS COLUMNS
		function calculateAnnualTotals() {
			var types = ["forecast", "actual"];
			//foreach group
			$j.each(groups, function(i, group){
				$j.each(types, function(idx, type){
					var budgetSel = "#forecast-budget-" + group; // annual budget column in green
					var annualSel = "#" + group + "Table #" + type + "-total";
					var dollarVarSel = "#" + type +"-budget-variance-dollar-" + group;
					var percentVarSel = "#" + type +"-budget-variance-percent-" + group;
					
					if (parseFloat($j(budgetSel).text()) != 0) {
						// variance from budget dollar
						$j(dollarVarSel).text((parseFloat($j(annualSel).text()) - parseFloat($j(budgetSel).text())).toFixed(2));
						// variance from budget percent
						$j(percentVarSel).text((parseFloat($j(dollarVarSel).text()) / parseFloat($j(budgetSel).text()) * 100).toFixed(2) + "%");
					}
					
					var budgetSel2 = "#forecast-budget2-" + group; // next fiscal year budget column in green
					var annualSel2 = "#" + group + "Table #" + type + "2-total";
					var dollarVarSel2 = "#" + type +"-budget-variance-dollar2-" + group;
					var percentVarSel2 = "#" + type +"-budget-variance-percent2-" + group;
					
					if (parseFloat($j(budgetSel2).text()) != 0) {
						// variance from budget dollar - next fiscal year
						$j(dollarVarSel2).text((parseFloat($j(annualSel2).text()) - parseFloat($j(budgetSel2).text())).toFixed(2));
						// variance from budget percent - next fiscal year
						$j(percentVarSel2).text((parseFloat($j(dollarVarSel2).text()) / parseFloat($j(budgetSel2).text()) * 100).toFixed(2) + "%");
					}
					
					
					// summary rows
					var budgetSel3 = "#forecast-budget-summary-" + group; 
					var annualSel3 = "#" + group + "Table #" + type + "-summary-total";
					var dollarVarSel3 = "#" + type +"-budget-variance-dollar-summary-" + group;
					var percentVarSel3 = "#" + type +"-budget-variance-percent-summary-" + group;
					
					if (parseFloat($j(budgetSel).text()) != 0) {

						// summary budget cell 
						$j(budgetSel3).text((parseFloat($j(budgetSel).text()) + parseFloat($j(budgetSel2).text())).toFixed(2));
						// variance dollar
						$j(dollarVarSel3).text((parseFloat($j(annualSel3).text()) - parseFloat($j(budgetSel3).text())).toFixed(2));
						// variance percent
						$j(percentVarSel3).text((parseFloat($j(dollarVarSel3).text()) / parseFloat($j(budgetSel3).text()) * 100).toFixed(2) + "%");
					}


				});
				
			});
			
			
			
			
			
		}
		
		
		// TOTALS COLUMN CALCULATOR
		function calculateTotals() {
			
			var classes = ["forecast", "actual", "variance", "prior-year-actual", "prior-year-variance", 
							"forecast2", "actual2", "variance2", "prior-year-actual2", "prior-year-variance2",
							"forecast-summary", "actual-summary", "variance-summary", 
							"prior-year-actual-summary", "prior-year-variance-summary"];
			
			//foreach group
			$j.each(groups, function(i, group){
				// foreach classes
				$j.each(classes, function(idx, item) {
					var tableSelector = "#" + group + "Table" ;
					var cellValue = 0;
					
					// each cell (get span and input values)
					$j(tableSelector).children().find("." + item).children(".anOutput, .anInput").each(function(index, cellItem) {
						var v = 0;
						
						if ($j(cellItem).hasClass("anOutput")) {
							v = parseFloat($j(cellItem).text());
						}
						else if ($j(cellItem).hasClass("anInput")) {
							v = parseFloat($j(cellItem).val());
						}
						
						cellValue += v;
					});
					
					// each cell values for summaries
					$j(tableSelector).children().find("." + item + ":not(:has(input, span))").each(function(index, cellItem) {
						var	v = parseFloat($j(cellItem).text());
						cellValue += v;
					});
					
					
					
					// total column
					var targetSelector = "#" +group + "Table #" + item + "-total";
					
					// format with 2 decimal place
					if (group != "Passenger") {
						cellValue = cellValue.toFixed(2);
					}
					
					$j(targetSelector).text(cellValue);
				});
			}); 
		}

		
		// PRIOR YEAR - VARIANCE SUMMARY
		function calculatePriorYearVarianceSummary() {

			$j(".prior-year-variance-summary").each(function(index, item) {
				var id = $j(item).attr("id");
				var columnIndex = $j(this).parent().children().index($j(this));
				var actualCellId = "#" + id.replace("prior-year-variance", "actual");
				var pyActualCellId = "#" + id.replace("variance", "actual");
				var cellValue = "-";
				
				if ($j(actualCellId).length > 0 && $j(pyActualCellId).length > 0) {
					cellValue = parseFloat($j(actualCellId).text()) - parseFloat($j(pyActualCellId).text()) 
				}
				
				// format with 2 decimal place
				if (id.indexOf("Passenger") == -1 && cellValue != "-") {
					cellValue = cellValue.toFixed(2);
				}
				
				$j("#" + id).text(cellValue);
			}); 
		
		}
		
		
		// VARIANCE SUMMARY
		function calculateVarianceSummary() {

			$j(".variance-summary").each(function(index, item) {
				var id = $j(item).attr("id");
				var columnIndex = $j(this).parent().children().index($j(this));
				var forecastCellId = "#" + id.replace("variance", "forecast");
				var actualCellId = "#" + id.replace("variance", "actual");
				var cellValue = "-";
				
				if ($j(forecastCellId).length > 0 && $j(actualCellId).length > 0) {
					cellValue = parseFloat($j(forecastCellId).text()) - parseFloat($j(actualCellId).text()) 
				}
				
				// format with 2 decimal place
				if (id.indexOf("Passenger") == -1 && cellValue != "-") {
					cellValue = cellValue.toFixed(2);
				}
				
				$j("#" + id).text(cellValue);
			}); 
		
		}


		// SUMMARY ROWS
		function calculateSummary(type) {

			$j("." + type + "-summary").each(function(index, item) {
				var id = $j(item).attr("id");
				var year = id.substring(id.lastIndexOf("-")+1);
				var columnIndex = $j(this).parent().children().index($j(this));
				
				// from cell
				var cellId = id.replace('-Summary','');
				var cellValue = "-";
				
				// span
				var spanSelector = "#" + cellId + " .anOutput";
				var inputSelector = "#" + cellId + " .anInput";
				
				// get values
				if ($j(spanSelector).length > 0) {
					cellValue = parseFloat($j(spanSelector).text())
					
					// add next year if found to summary
					var nySelector = "#" + cellId.replace(year, parseInt(year)+1) + " .anOutput";
					//console.log("NY: " + nySelector);
					
					// only for the final year
					if (year > fy && $j(nySelector).length > 0) {
						cellValue += parseFloat($j(nySelector).text());  
					}
					
				}
				else {
					cellValue = parseFloat($j(inputSelector).val())
					
					// add next year if found to summary
					var nySelector = "#" + cellId.replace(year, parseInt(year)+1) + " .anInput";
					//console.log("NY: " + nySelector);
					
					// only for the final year
					if (year > fy && $j(nySelector).length > 0) {
						cellValue += parseFloat($j(nySelector).val());  
					}
					
				}
				
				// format with 2 decimal place
				if (id.indexOf("Passenger") == -1 && cellValue != "-") {
					cellValue = cellValue.toFixed(2);
				}
				
				$j("#" + id).text(cellValue);
			}); 
		
		}
		
		function showSaving() {
			$j("#saveScreen").dialog("open");
			$j(".ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix").hide();
			
		}
		
		function doReload() {
			document.getElementById("reloadLink").click();
		}
		
	</script>
	<apex:pageMessages />
	<apex:form id="mainForm">
		<apex:pageBlock id="myBlock">
			<apex:pageBlockButtons styleClass="buttonSet">
				<apex:commandButton value="Save Forecasting Table" oncomplete="doReload()" onclick="showSaving()" action="{!doSave}"/>
			</apex:pageBlockButtons>
		
			<apex:outputPanel id="myPanel">
				<ul id="tabs">
				<apex:repeat value="{!forecastList}" var="group">
					<li><a id="{!group}Tab" class="tabLink">{!group} {!IF(group=='Passenger','#','$')}</a></li>
				</apex:repeat>
				</ul>
				
				<div id="tabWrapper">
					<apex:repeat value="{!forecastList}" var="group">
					<!-- {!group} -->
						<div class="tabContent">
							<table class="wrapper" id="{!group}Table">
								<tr>
									<td>
										<table class="names">
											<!-- CURRENT YEAR -->
											<tr>
												<td class="head section">{!group}</td>
											</tr>
											<tr>
												<td>{!Forecast__c.Year__c} {!group} - Forecast</td>
											</tr>
											<tr>
												<td>Actual</td>
											</tr>
											<tr>
												<td>Variance</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td>Prior Year Actual</td>
											</tr>
											<tr>
												<td>Variance</td>
											</tr>
											<tr>
												<td class="separator"></td>
											</tr>
										</table>
									</td>
									<apex:repeat value="{!forecastMap[group]}" var="item" rows="18">
										<td>
											<table class="forecasting">
				
												<tr>
													<td class="head {!item.YearType}"><span>{!item.MonthShort}</span>
														<br /> <span>{!item.Year}</span></td>
												</tr>
												<tr>
													<td id="forecast-{!item.ID}" class="forecast {!IF(item.Editable,'editable','')}">
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Revenue__c}" rendered="{!item.Editable && group == 'Booking'}" /> 
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Spend__c}" rendered="{!item.Editable && group == 'Marketing'}" />
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Count__c}" rendered="{!item.Editable && group == 'Passenger'}" />
														
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Revenue__c}" rendered="{!item.Editable==false && group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Spend__c}" rendered="{!item.Editable==false && group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Count__c}" rendered="{!item.Editable==false && group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="actual-{!item.ID}" class="actual">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="variance-{!item.ID}" class="variance">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Revenue__c-item.FM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Spend__c-item.FM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Count__c-item.FM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td class="spacer"></td>
												</tr>
												<tr>
													<td id="prior-year-actual-{!item.ID}" class="prior-year-actual">
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="prior-year-variance-{!item.ID}" class="prior-year-variance">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Revenue__c-item.PriorYFM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Spend__c-item.PriorYFM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Count__c-item.PriorYFM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td class="separator"></td>
												</tr>
											</table>
										</td>
									</apex:repeat>
									<td>
										<table class="subTotals">
											<!-- CURRENT YEAR -->
											<tr>
												<td class="head subTotal">Total</td>
											</tr>
											<tr>
												<td id="forecast-total" class="group-{!group}">0</td>
											</tr>
											<tr>
												<td id="actual-total" class="group-{!group}">0</td>
											</tr>
											<tr>
												<td id="variance-total" class="group-{!group}">0</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td id="prior-year-actual-total" class="group-{!group}">0</td>
											</tr>
											<tr>
												<td id="prior-year-variance-total" class="group-{!group}">0</td>
											</tr>
											<tr>
												<td class="separator"></td>
											</tr>
										</table>
									
									</td>
									<td>
										<table class="totals">
											<!-- CURRENT YEAR -->
											<tr>
												<td></td>
												<td class="head">Annual<br/>Budget</td>
												<td class="head">Variance from<br/>Budget $</td>
												<td class="head">Variance from<br/>Budget %</td>
											</tr>
											<tr>
												<td></td>
												<td class="green" id="forecast-budget-{!group}">
													{!IF(group=='Booking',Forecast__c.Budget_Booking_Revenue__c,'')}
													{!IF(group=='Passenger',Forecast__c.Budget_Passenger_Count__c,'')}
													{!IF(group=='Marketing',Forecast__c.Budget_Marketing_Spend__c,'')}
												</td>
												<td id="forecast-budget-variance-dollar-{!group}">0</td>
												<td id="forecast-budget-variance-percent-{!group}">0%</td>
											</tr>
											<tr>
												<td></td>
												<td class="no-border-left no-border-bottom"></td>
												<td id="actual-budget-variance-dollar-{!group}">0</td>
												<td id="actual-budget-variance-percent-{!group}">0%</td>
											</tr>
										</table>
									</td>
								</tr>
								<!-- FINAL YEAR START -->
								<tr>
									<td>
										<table class="names">
											<tr>
												<td class="head next no-border-top no-border-right no-border-left no-shade"></td>
											</tr>
											<tr>
												<td>{!VALUE(Forecast__c.Year__c)+2}
													{!group} - Forecast</td>
											</tr>
											<tr>
												<td>Actual</td>
											</tr>
											<tr>
												<td>Variance</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td>Prior Year Actual</td>
											</tr>
											<tr>
												<td>Variance</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td>Comments</td>
											</tr>
											<tr>
												<td class="separator"></td>
											</tr>
										</table>
									</td>
									<td colspan="12">
										
									</td>
									<apex:repeat value="{!forecastMap[group]}" var="item" first="18">
										<td >
											<table class="forecasting">
				
												<tr>
													<td class="head {!item.YearType}"><span>{!item.MonthShort}</span>
														<br /> <span>{!item.Year}</span></td>
												</tr>
												<tr>
													<td id="forecast-{!item.ID}" class="forecast2 {!IF(item.Editable,'editable','')}">
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Revenue__c}" rendered="{!item.Editable && group == 'Booking'}" /> 
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Spend__c}" rendered="{!item.Editable && group == 'Marketing'}" />
														<apex:inputText styleClass="anInput" value="{!item.FM.Forecast_Count__c}" rendered="{!item.Editable && group == 'Passenger'}" />
														
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Revenue__c}" rendered="{!item.Editable==false && group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Spend__c}" rendered="{!item.Editable==false && group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Count__c}" rendered="{!item.Editable==false && group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="actual-{!item.ID}" class="actual2">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="variance-{!item.ID}" class="variance2">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Revenue__c-item.FM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Spend__c-item.FM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Forecast_Count__c-item.FM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td class="spacer"></td>
												</tr>
												<tr>
													<td id="prior-year-actual-{!item.ID}" class="prior-year-actual2">
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.PriorYFM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td id="prior-year-variance-{!item.ID}" class="prior-year-variance2">
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Revenue__c-item.PriorYFM.Actual_Revenue__c}" rendered="{!group == 'Booking'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Spend__c-item.PriorYFM.Actual_Spend__c}" rendered="{!group == 'Marketing'}" />
														<apex:outputText styleClass="anOutput" value="{!item.FM.Actual_Count__c-item.PriorYFM.Actual_Count__c}" rendered="{!group == 'Passenger'}" />
													</td>
												</tr>
												<tr>
													<td class="spacer"></td>
												</tr>
												<tr>
													<td class="commentCell">
														<apex:inputText styleClass="commentInput" tabindex="19" maxlength="255" value="{!item.FM.Comment__c}" rendered="{!item.IsPlaceholder!=true}"/>
													</td>
												</tr>
												<tr>
													<td class="separator"></td>
												</tr>
											</table>
										</td>
									</apex:repeat>
									<td>
										<table class="subTotals">
											<tr>
												<td class="head no-border-top no-border-right no-border-left no-shade"></td>
											</tr>
											<tr>
												<td id="forecast2-total">0</td>
											</tr>
											<tr>
												<td id="actual2-total">0</td>
											</tr>
											<tr>
												<td id="variance2-total">0</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td id="prior-year-actual2-total">0</td>
											</tr>
											<tr>
												<td id="prior-year-variance2-total">0</td>
											</tr>
											<tr>
												<td class="separator"></td>
											</tr>
										</table>
									
									</td>
									<td>
										<table class="totals">
											<tr>
												<td></td>
												<td class="head no-border-top no-border-right no-border-left no-shade"></td>
												<td class="head no-border-top no-border-right no-border-left no-shade"></td>
												<td class="head no-border-top no-border-right no-border-left no-shade"></td>
											</tr>
											<tr>
												<td></td>
												<td id="forecast-budget2-{!group}" class="green">
													{!IF(group=='Booking',forecastNFY.Budget_Booking_Revenue__c/2,'')}
													{!IF(group=='Passenger',forecastNFY.Budget_Passenger_Count__c/2,'')}
													{!IF(group=='Marketing',forecastNFY.Budget_Marketing_Spend__c/2,'')}
												</td>
												<td id="forecast-budget-variance-dollar2-{!group}">0</td>
												<td id="forecast-budget-variance-percent2-{!group}">0%</td>
											</tr>
											<tr>
												<td></td>
												<td class="no-border-left no-border-bottom"></td>
												<td id="actual-budget-variance-dollar2-{!group}">0</td>
												<td id="actual-budget-variance-percent2-{!group}">0%</td>
											</tr>
										</table>
									</td>
								</tr>
								<!-- SUMMARY START -->
								<tr>
									<td>
										<table class="names">
											<tr>
												<td class="summary">Summary</td>
											</tr>
											<tr>
												<td>Total Forecast</td>
											</tr>
											<tr>
												<td>Total Actual</td>
											</tr>
											<tr>
												<td>Total Variance</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td>Prior Year Actual</td>
											</tr>
											<tr>
												<td>Variance</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td>Comments</td>
											</tr>
										</table>
									</td>
								
									<apex:repeat value="{!forecastMap[group]}" var="item" rows="18">
										<td>
											<table class="forecasting">
												<tr>
													<td class="summary no-border-top no-border-right no-border-left"></td>
												</tr>
												<tr>
													<td id="forecast-Summary-{!item.ID}" class="forecast-summary">0</td>
												</tr>
												<tr>
													<td id="actual-Summary-{!item.ID}" class="actual-summary">0</td>
												</tr>
												<tr>
													<td id="variance-Summary-{!item.ID}" class="variance-summary">0</td>
												</tr>
												<tr>
													<td class="spacer"></td>
												</tr>
												<tr>
													<td id="prior-year-actual-Summary-{!item.ID}" class="prior-year-actual-summary">0</td>
												</tr>
												<tr>
													<td id="prior-year-variance-Summary-{!item.ID}" class="prior-year-variance-summary">0</td>
												</tr>
												<tr>
													<td class="spacer {!IF(item.IsPlaceholder==true, 'no-border-bottom', '')}"></td>
												</tr>
												<tr>
													<td class="commentCell {!IF(item.IsPlaceholder==true, 'placeholder no-border-top no-border-right no-border-bottom no-border-left ', '')}">
														<apex:inputText tabindex="25" styleClass="commentInput" maxlength="255" value="{!item.FM.Comment__c}" rendered="{!item.IsPlaceholder!=true}"/>
													</td>
												</tr>
											</table>
										</td>
									</apex:repeat>
									<td>
										<table class="subTotals">
											<!-- CURRENT YEAR -->
											<tr>
												<td class="summary no-border-top no-border-right no-border-left"></td>
											</tr>
											<tr>
												<td id="forecast-summary-total">0</td>
											</tr>
											<tr>
												<td id="actual-summary-total">0</td>
											</tr>
											<tr>
												<td id="variance-summary-total">0</td>
											</tr>
											<tr>
												<td class="spacer"></td>
											</tr>
											<tr>
												<td id="prior-year-actual-summary-total">0</td>
											</tr>
											<tr>
												<td id="prior-year-variance-summary-total">0</td>
											</tr>
										</table>
									
									</td>
									<td>
									
										<table class="totals">
											<tr>
												<td></td>
												<td class="summary no-border-top no-border-right no-border-left no-shade"></td>
												<td class="summary no-border-top no-border-right no-border-left no-shade"></td>
												<td class="summary no-border-top no-border-right no-border-left no-shade"></td>
											</tr>
											<tr>
												<td></td>
												<td id="forecast-budget-summary-{!group}" class="green">0</td>
												<td id="forecast-budget-variance-dollar-summary-{!group}">0</td>
												<td id="forecast-budget-variance-percent-summary-{!group}">0%</td>
											</tr>
											<tr>
												<td></td>
												<td class="no-border-left no-border-bottom"></td>
												<td id="actual-budget-variance-dollar-summary-{!group}">0</td>
												<td id="actual-budget-variance-percent-summary-{!group}">0%</td>
											</tr>
										</table>					
									</td>
								</tr>
							</table>
						</div>
					</apex:repeat>
				</div>
				
				
				
			</apex:outputPanel>
		</apex:pageBlock>
	</apex:form>
	
	<div id="commentEditor"><textarea id="comment" name="comment"></textarea></div>
	<div id="saveScreen" style="text-align:center; color: green; font-weight: bold;">Saving changes</div>
	<a href="/{!Forecast__c.Id}" target="_top" id="reloadLink"></a>
</apex:page>